from typing import Generic, Any, TypeVar, List, Optional
from pydantic import BaseModel

T = TypeVar("T")

# 共用返回格式
class RETURN(BaseModel, Generic[T]):
    code: bool
    data: T
    msg: str

    @staticmethod
    def success(msg: str = "success", data: T = None) -> "RETURN":
        return RETURN(code=True, msg=msg, data=data)

    @staticmethod
    def fail(msg: str = "fail", data: T = None) -> "RETURN":
        return RETURN(code=False, msg=msg, data=data)

# 查询条件的格式
class Filter(BaseModel):
    field: str
    operator: str
    value: Any

# 返回列表的格式
class ListResponse(BaseModel, Generic[T]):
    list: List[T]
    total: int
    pageSize: int
    currentPage: int

# 分页查询的格式
class ListRequest(BaseModel):
    page: int = 1
    limit: int = 10
    sort: str = 'id'
    order: str = 'desc'
    fields: Optional[List[str]] = []
    filter: Optional[List[Filter]] = []

# 文件上传的返回格式
class ResponseFile(BaseModel):
    full_path: str
    path: str
    


